package com.hxz.graduationdesign.controller;

import com.hxz.graduationdesign.base.response.JsonResult;
import com.hxz.graduationdesign.pojo.vo.UpVideoVo;
import com.hxz.graduationdesign.pojo.vo.VideoVo;
import com.hxz.graduationdesign.service.IVideoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.hxz.graduationdesign.base.response.StatusCode.VIDEO_ADD_FAILED;

@Slf4j
@RestController
@RequestMapping("/v1/video/")
public class VideoController {

    @Autowired
    private IVideoService videoService;

    @PostMapping("query/{bv}")
    public JsonResult queryVideo(@PathVariable String bv){

        log.debug("查询视频bv:"+bv);
        VideoVo videoVo = videoService.queryVideo(bv);
        return videoVo!=null?JsonResult.ok(videoVo):new JsonResult(VIDEO_ADD_FAILED);

    }

    @PostMapping("queryUp/{uid}")
    public JsonResult queryUpVideo(@PathVariable String uid){

        List<UpVideoVo> upVideoVos = videoService.queryUpVideo(uid);
        if (upVideoVos==null){
            return new JsonResult(VIDEO_ADD_FAILED);
        }
        return JsonResult.ok(upVideoVos);
    }

    @PostMapping("updateUp/{uid}")
    public JsonResult updateUpVideo(@PathVariable String uid){

        List<UpVideoVo> upVideoVos = videoService.updateUpVideo(uid);

        return JsonResult.ok(upVideoVos);

    }

    @PostMapping("update/{bv}")
    public JsonResult updateVideo(@PathVariable String bv){

        VideoVo videoVo = videoService.updateSingleVideo(bv);

        return JsonResult.ok(videoVo);

    }

}
